import Taro from '@tarojs/taro'
import app from '../../../../main.js'
let myJs = {
    getData: function() {
        this.state = {
            topic_id: this.$router.params.topic_id,
            type: this.$router.params.type,
            content: '',
            images: [],
            video: this.$router.params.video,
            videoPath: ''
        };
        return this.state;
    },
    createChat() {
        var me = this;
        var data = me.state.chat;
        var flag = true;
        if(me.beforeCreateChat) {
            flag = me.beforeCreateChat(data);
        }
        if(flag) {
            app.post("api/chats/create", data, function(res) {
                if(me.afterCreateChat) {
                    me.afterCreateChat(res);
                }
            });
        }
    },
    createChatMessage() {
        var me = this;
        var data = me.state.chat_message;
        var flag = true;
        if(me.beforeCreateChatMessage) {
            flag = me.beforeCreateChatMessage(data);
        }
        if(flag) {
            app.post("api/chat_messages/create", data, function(res) {
                if(me.afterCreateChatMessage) {
                    me.afterCreateChatMessage(res);
                }
            });
        }
    },
    componentWillMount () {
        if(this.init) {
            this.init();
        }
        console.log("执行了吗")
        if(this.$router.params.blurl){
            console.log('setState是否起作用',typeof this.$router.params.blurl)
            let blurl = this.$router.params.blurl;
            let content = `病历链接:\n`;
            this.setState({
                content:content,
                type:'图片'
            })
        }
    },
    navigateTo(url) {
        app.navigateTo(url);
    },
    handleChange(name, v) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = v;
        console.log(temp[names[i]]);
        this.setState({n: temp[names[i]]});
    },
    // handleTextareaChange(name, e) {
    //     var names = name.split('.');
    //     var n = names[0];
    //     var temp = this.state;
    //     for(var i = 0; i < names.length - 1; i++) {
    //         temp = temp[names[i]];
    //     }
    //     temp[names[i]] = e.target.value;
    //     this.setState({n: temp[names[i]]});
    // },
    redirectTo(url) {
        app.redirectTo(url);
    },
    componentDidMount () {},
    componentWillUnmount () {},
    componentDidHide () {}
}
export default myJs;
